<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$cookie = $this->get_facebook_cookie('123773181307','69f883df40665ca86f54e1a34eb12b14');
		$user = json_decode(file_get_contents( 'https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
		$data['cookie'] = $cookie;
		$data['user'] = $user;
		$this->load->view('home', $data);
	}
	public function get_facebook_cookie($app_id, $app_secret) {
	  $args = array();
	  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
	  ksort($args);
	  $payload = '';
	  foreach ($args as $key => $value) {
	    if ($key != 'sig') {
	      $payload .= $key . '=' . $value;
	    }
	  }
	  if (md5($payload . $app_secret) != $args['sig']) {
	    return null;
	  }
	  return $args;
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
